﻿Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports DotNetNuke
Namespace NVPortal.Modules.NVNews

    Public MustInherit Class Vnexpress
        Inherits Entities.Modules.PortalModuleBase

#Region "Controls"
#End Region

#Region "Event Handlers"
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Try
                If Not IsPostBack Then

                    Dim DisplayNumber As Integer
                    If Settings("NVNewsDisplayNumberSetting") <> "" Then
                        DisplayNumber = Settings("NVNewsDisplayNumberSetting")
                    Else
                        DisplayNumber = "1" ' 1 row and 1 col
                    End If

                    'Cac tin khac cung chuyen muc voi tin nay
                    Dim arrNews As New ArrayList
                    Dim ctlNews As New NV_NewsController
                    arrNews = ctlNews.SelectCustomeNews(IIf(Settings("NVNewsCategorySetting") <> "", Settings("NVNewsCategorySetting"), 0), Settings("PortalSetting"), DisplayNumber + 1)
                    Dim clthotnew As New NV_NewsInfo
                    If arrNews.Count > 0 Then
                        Dim objNews As NV_NewsInfo
                        objNews = CType(arrNews(0), NV_NewsInfo)
                        Me.lbSummary.Text = objNews.Summary
                        Me.hplTitle.Text = objNews.Title
                        Me.hplTitle.NavigateUrl = FormatURL(objNews.NewId, ReplaceChuoi(objNews.Title))
                        Me.hplImgnews.NavigateUrl = FormatURL(objNews.NewId, ReplaceChuoi(objNews.Title))
                        If objNews.ImagePath <> "" Then
                            If objNews.ImagePath.Contains("http://") Then
                                Me.imgNews.Visible = True
                                Me.imgNews.ImageUrl = objNews.ImagePath

                            Else
                                Me.imgNews.Visible = True
                                Me.imgNews.ImageUrl = objNews.ImagePath
                            End If
                        Else
                            Me.imgNews.Visible = False
                        End If
                        If Settings("NVNewsImageValueSetting") <> "" Then
                            Me.imgNews.Width = CInt(Split(Settings("NVNewsImageValueSetting"))(0))
                        Else
                            Me.imgNews.Width = 60
                        End If
                        'Me.lbDatetime.Text = objNews.Createdate.ToString("HH:mm:ss - d/M/yyyy")
                        'Me.lblluotxem.text = objNews.Solandoc
                        Dim cltFeed As New NV_NewsFeedbackController
                        'Dim arrFeed As New ArrayList
                        'arrFeed = cltFeed.GetByNewsId(objNews.NewId)
                        'Me.lbsbc.Text = arrFeed.Count
                        'Me.hplBC.NavigateUrl = FormatURLComment(objNews.NewId, ReplaceChuoi(objNews.Title))

                        If Me.lbSummary.Visible = False Then
                            Me.hplTitle.ToolTip = objNews.Summary
                        End If

                        Dim objNews2 As NV_NewsInfo
                        objNews2 = CType(arrNews(1), NV_NewsInfo)
                        Me.hplTitle2.Text = objNews2.Title
                        Me.hplTitle2.NavigateUrl = FormatURL(objNews2.NewId, ReplaceChuoi(objNews2.Title))
                        Me.hplImgnews2.NavigateUrl = FormatURL(objNews2.NewId, ReplaceChuoi(objNews2.Title))
                        If objNews2.ImagePath <> "" Then
                            If objNews2.ImagePath.Contains("http://") Then
                                Me.imgNews2.Visible = True
                                Me.imgNews2.ImageUrl = objNews.ImagePath

                            Else
                                Me.imgNews2.Visible = True
                                Me.imgNews2.ImageUrl = objNews2.ImagePath
                            End If
                        Else
                            Me.imgNews2.Visible = False
                        End If

                        'Me.lbDatetime2.Text = objNews2.Createdate.ToString("HH:mm:ss - d/M/yyyy")
                        Dim arrFeed2 As New ArrayList
                        'arrFeed2 = cltFeed.GetByNewsId(objNews2.NewId)
                        'Me.lbsbc2.Text = arrFeed2.Count
                        'Me.hplBC2.NavigateUrl = FormatURLComment(objNews2.NewId, ReplaceChuoi(objNews2.Title))

                        arrNews.RemoveAt(0)
                        arrNews.RemoveAt(0)
                        Me.drgOtherNewsRight.DataSource = arrNews
                        Me.drgOtherNewsRight.DataBind()

                        Dim ctlNewsCategories As New NV_NewsCategoriesController
                        Dim arrNewsCategories As New ArrayList
                    End If

                End If
            Catch ex As Exception
                'Me.imgNews.Visible = False
                ' Exception
                ProcessModuleLoadException(Me, ex)
            End Try
        End Sub
        Public Function CatName(ByVal catid As String) As String
            Dim ctlCat As New NV_NewsCategoriesController
            Dim objCat As NV_NewsCategoriesInfo
            objCat = ctlCat.GetByID(catid)
            Return objCat.CategoryName
        End Function
        Public Function ReplaceChuoi(ByVal chuoi As String) As String
            Dim convert As String = Global.ReplaceChuoi.bodau(chuoi).Replace(" ", "-")
            Return convert
        End Function
        Public Function FormatURL(ByVal strID As String, ByVal strLink As String) As String
            Return "/" & Settings("NVNewsDisplayPageSetting") & "/" & strID & "/" & ReplaceChuoi(strLink) & ".htm"
        End Function
        Public Function FormatURLComment(ByVal sitem As String, ByVal strID As String, ByVal strLink As String) As String
            Return "/" & sitem & "/" & strID & "/" & ReplaceChuoi(strLink) & ".htm#DetailComment"
        End Function
#End Region

#Region "Optional Interfaces"

#End Region
        Protected Sub drgOtherNewsRight_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles drgOtherNewsRight.ItemDataBound
            If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
                Dim imgNews2 As Image
                imgNews2 = CType(e.Item.FindControl("ImageTitle"), Image)
                Dim obj As NV_NewsInfo
                obj = New NV_NewsController().GetByID(drgOtherNewsRight.DataKeys(e.Item.ItemIndex))
            End If
        End Sub
    End Class

End Namespace
